//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package gitlab_triger

import (
	"fmt"
	"testing"
)

const _PUSH_HOOK_DATA = `
{
    "object_kind": "push",
    "event_name": "push",
    "before": "dc246b8a299056d171bf5d72fc05cb1a5b0a4408",
    "after": "dc246b8a299056d171bf5d72fc05cb1a5b0a4408",
    "ref": "refs/heads/master",
    "ref_protected": true,
    "checkout_sha": "dc246b8a299056d171bf5d72fc05cb1a5b0a4408",
    "message": null,
    "user_id": 1,
    "user_name": "Administrator",
    "user_username": "root",
    "user_email": null,
    "user_avatar": "https://www.gravatar.com/avatar/b4b328dfb4d8a2743e6cb237b1b82b478b11a7e317528d9e8ebb1a1d6355c4a9?s=80&d=identicon",
    "project_id": 1,
    "project": {
        "id": 1,
        "name": "test·",
        "description": null,
        "web_url": "http://09b00b609eb5/g1/test",
        "avatar_url": null,
        "git_ssh_url": "git@09b00b609eb5:g1/test.git",
        "git_http_url": "http://09b00b609eb5/g1/test.git",
        "namespace": "g1",
        "visibility_level": 0,
        "path_with_namespace": "g1/test",
        "default_branch": "master",
        "ci_config_path": null,
        "homepage": "http://09b00b609eb5/g1/test",
        "url": "git@09b00b609eb5:g1/test.git",
        "ssh_url": "git@09b00b609eb5:g1/test.git",
        "http_url": "http://09b00b609eb5/g1/test.git"
    },
    "commits": [
        {
            "id": "dc246b8a299056d171bf5d72fc05cb1a5b0a4408",
            "message": "Initialized from 'Go Micro' project template\n\nTemplate repository: https://gitlab.com/gitlab-org/project-templates/go-micro\nCommit SHA: 6b4d4bebe6cdd9932b14d81e97a59f9f8b58d224\n",
            "title": "Initialized from 'Go Micro' project template",
            "timestamp": "2023-11-02T17:47:52+01:00",
            "url": "http://09b00b609eb5/g1/test/-/commit/dc246b8a299056d171bf5d72fc05cb1a5b0a4408",
            "author": {
                "name": "GitLab",
                "email": "root@localhost"
            },
            "added": [
                ".gitlab-ci.yml",
                "CONTRIBUTING.md",
                "LICENSE",
                "README.md",
                "go.mod",
                "go.sum",
                "main.go",
                "proto/greeter.pb.go",
                "proto/greeter.pb.micro.go",
                "proto/greeter.proto"
            ],
            "modified": [],
            "removed": []
        }
    ],
    "total_commits_count": 1,
    "push_options": {},
    "repository": {
        "name": "test·",
        "url": "git@09b00b609eb5:g1/test.git",
        "description": null,
        "homepage": "http://09b00b609eb5/g1/test",
        "git_http_url": "http://09b00b609eb5/g1/test.git",
        "git_ssh_url": "git@09b00b609eb5:g1/test.git",
        "visibility_level": 0
    }
}
`

func TestExtractPushHookAttr(t *testing.T) {
	attrList, err := ExtractPushHookAttr([]byte(_PUSH_HOOK_DATA))
	if err != nil {
		t.Fatal(err)
		t.FailNow()
	}
	fmt.Println(attrList)
}
